home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / dnalib59.arj / LINEEDIT.BAS < prev    next >
BASIC Source File  |  1993-12-15  |  4KB  |  182 lines

  1. DECLARE SUB CalcByte(Attr%,LowByte%,HiByte%)
  2. DECLARE SUB Clicked(Rgt%,Lft%,Row%,Col%)
  3. DECLARE SUB HideCursor()
  4. DECLARE SUB ShowCursor()
  5. DECLARE FUNCTION InsertKey%()
  6. DECLARE FUNCTION LeftButtonReleased%()
  7.  
  8. SUB LineEdit(Allow$,Text$,Mouse%,MouseRow%,MouseCol%,Fill%,Row%,Col%,EditKey%,Attr%) PUBLIC
  9.  
  10. CalcByte Attr%,FGround%,BGround%
  11.  
  12. IF Mouse% THEN HideCursor
  13.  
  14. Finished% = 0
  15.  
  16. LOCATE Row%,Col%
  17. COLOR FGround%,BGround%
  18.  
  19. IF Text$ = STRING$(LEN(Text$),32) THEN
  20.   Temp$ = STRING$(LEN(Text$),Fill%)
  21.   PRINT Temp$;
  22. ELSE
  23.   a% = LEN(Text$):b% = LEN(RTRIM$(Text$))
  24.   Temp$ = RTRIM$(Text$) + STRING$(a% - b%,Fill%)
  25.   PRINT Temp$;
  26. END IF
  27.  
  28. IF Editkey% = 255 THEN EXIT SUB
  29.  
  30. CursorPosition% = Col% + b%
  31.  
  32. DO
  33.  
  34. IF CursorPosition% = Col% + LEN(Text$) THEN
  35.   LOCATE Row%,CursorPosition%,0
  36. ELSE
  37.   IF InsertKey% THEN
  38.     LOCATE Row%,CursorPosition%,1,0,13    'Block Cusor
  39.   ELSE
  40.     LOCATE Row%,CursorPosition%,1,11,12   'Normal Cursor
  41.   END IF
  42. END IF
  43.  
  44. WHILE NOT INSTAT
  45.   IF Mouse% THEN
  46.     ShowCursor
  47.     Clicked Rgt%,Lft%,MRow%,MCol%
  48.     IF LeftButtonReleased% THEN
  49.       MouseRow% = MRow%
  50.       MouseCol% = MCol%
  51.       Editkey% = -255
  52.       GOTO KeyBoardRoutine
  53.     END IF
  54.   END IF
  55. WEND
  56. Ky$ = INKEY$
  57.  
  58.  
  59. IF LEN(Ky$) = 1 THEN
  60.   EditKey% = ASC(Ky$)
  61. ELSE
  62.   EditKey% = -ASC(RIGHT$(Ky$,1))
  63. END IF
  64.  
  65. KeyBoardRoutine:
  66.  
  67. SELECT CASE EditKey%
  68.  
  69.     CASE 8     'BackSpace
  70.  
  71.       IF CursorPosition% > Col% THEN
  72.         A$ = LEFT$(Temp$,CursorPosition% - Col% - 1)
  73.         B$ = RIGHT$(Temp$,Col% + LEN(Text$) - CursorPosition%)
  74.         Temp$ = A$ + B$ + STRING$(LEN(Text$) - LEN(A$ + B$),Fill%)
  75.         DECR CursorPosition%
  76.             IF Mouse% THEN HideCursor
  77.         LOCATE Row%,Col%
  78.         PRINT Temp$;
  79.       END IF
  80.  
  81.     CASE 13,9,-72,-80  'EnterKey TabKey Up/Down ArrowKey
  82.  
  83.       A$ = LTRIM$(RTRIM$(Temp$,CHR$(Fill%)))
  84.       Text$ = A$ + SPACE$(LEN(Text$) - LEN(A$))
  85.       Finished% = 1
  86.  
  87.     CASE 27    'EscKey
  88.  
  89.       LOCATE Row%,Col%
  90.       COLOR FGround%,BGround%
  91.  
  92.       IF Text$ = STRING$(LEN(Text$),32) THEN
  93.         Temp$ = STRING$(LEN(Text$),Fill%)
  94.             IF Mouse% THEN HideCursor
  95.         PRINT Temp$;
  96.       ELSE
  97.         a% = LEN(Text$):b% = LEN(RTRIM$(Text$))
  98.         Temp$ = RTRIM$(Text$) + STRING$(a% - b%,Fill%)
  99.             IF Mouse% THEN HideCursor
  100.         PRINT Temp$;
  101.       END IF
  102.  
  103.       Finished% = 1
  104.  
  105.     CASE -71   'HomeKey
  106.  
  107.       CursorPosition% = Col%
  108.  
  109.     CASE -75   'LeftArrow
  110.  
  111.       IF CursorPosition% > Col% THEN
  112.         DECR CursorPosition%
  113.       END IF
  114.  
  115.     CASE -77   'RightArrow
  116.  
  117.       IF CursorPosition% < Col% + LEN(RTRIM$(Temp$,(CHR$(Fill%)))) THEN
  118.         INCR CursorPosition%
  119.       END IF
  120.  
  121.     CASE -79   'EndKey
  122.  
  123.       CursorPosition% = Col% + LEN(RTRIM$(Temp$,(CHR$(Fill%))))
  124.  
  125.     CASE -82   'InsertKey
  126.  
  127.       IF InsertKey% THEN
  128.         LOCATE ,,,0,13
  129.       ELSE
  130.         LOCATE ,,,11,12
  131.       END IF
  132.  
  133.     CASE -83   'DeleteKey
  134.  
  135.       IF CursorPositon% > Col% - 1 OR CursorPosition% < Col% + LEN(Text$) THEN
  136.         A$ = LEFT$(Temp$,CursorPosition% - Col%)
  137.         B$ = RIGHT$(Temp$,Col% + LEN(Text$) - CursorPosition% - 1)
  138.         Temp$ = A$ + B$ + STRING$(LEN(Text$) - LEN(A$ + B$),Fill%)
  139.             IF Mouse% THEN HideCursor
  140.         LOCATE Row%,Col%
  141.         PRINT Temp$;
  142.       END IF
  143.  
  144.     CASE 32 TO 254
  145.       IF CursorPosition% < Col% + LEN(Text$) THEN
  146.             IF INSTR(Ky$,ANY (Allow$)) THEN
  147.           IF InsertKey% THEN
  148.         A$ = LEFT$(Temp$,CursorPosition% - Col%)
  149.         B$ = RIGHT$(Temp$,Col% + LEN(Text$) - (CursorPosition% + 1))
  150.         Temp$ = A$ + Ky$ + B$
  151.                 IF Mouse% THEN HideCursor
  152.         LOCATE Row%,Col%
  153.         PRINT Temp$;
  154.         INCR CursorPosition%
  155.           ELSE
  156.             A$ = LEFT$(Temp$,CursorPosition% - Col%)
  157.             B$ = RIGHT$(Temp$,Col% + LEN(Text$) - CursorPosition%)
  158.             C$ = LEFT$(B$,LEN(B$) - 1)
  159.             Temp$ = A$ + Ky$ + C$
  160.                 IF Mouse% THEN HideCursor
  161.             LOCATE Row%,Col%
  162.             PRINT Temp$;
  163.             INCR CursorPosition%
  164.           END IF
  165.             END IF
  166.       END IF
  167.  
  168.     CASE -255 'exit with mouse
  169.           A$ = LTRIM$(RTRIM$(Temp$,CHR$(Fill%)))
  170.       Text$ = A$ + SPACE$(LEN(Text$) - LEN(A$))
  171.       Finished% = 1
  172.  
  173.         CASE ELSE
  174.       BEEP
  175.  
  176. END SELECT
  177.  
  178. LOOP UNTIL Finished% = 1
  179.  
  180. END SUB
  181.  
  182.